package bhbt.controller.admin.info;


import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import bhbt.controller.core.BaseController;
import bhbt.model.Admin;
import bhbt.service.AdminService;
import bhbt.utils.ContextUtil;
import bhbt.utils.MapUtil;
import bhbt.utils.SysConst;






/**
 * Created by Administrator on 2016/3/25.
 */
@Controller
 
public class UpdateSelfController extends BaseController {
    @Resource
    private AdminService adminService;
   
   

    @RequestMapping("admin/info/updateSelfShow.shtml")
    public String show(ModelMap model,HttpServletRequest request,HttpSession session) throws Exception{
        Map formMap = getParameterMap(request);
        Admin admin = ContextUtil.getAdmin();
        request.setAttribute("admin",admin);
		//修改缓存
		
		return "admin/info/updateSelf";
    	
        
        
    }
    
    @RequestMapping("admin/info/updateSelf.shtml")
    public String update(Admin admin,ModelMap model,HttpServletRequest request,HttpSession session) throws Exception{
        Map formMap = getParameterMap(request);
        int id = MapUtil.getIntValue(formMap, "id");
        
        if(0 < id){
        	
        	Map mapAdmin = new HashMap();
        	mapAdmin.put("id",admin.getId());
        	mapAdmin.put("title",MapUtil.getString(formMap,"title"));
        	mapAdmin.put("personName",MapUtil.getString(formMap,"personName"));
        	mapAdmin.put("tel",MapUtil.getString(formMap,"tel"));
        	 
        	adminService.update(mapAdmin);
    		setMessage(model,"修改成功。");
    		Boolean result = true;
    		request.setAttribute("result", result);
    		admin=adminService.getByKey(id);
    		//修改缓存
    		session.setAttribute(SysConst.MG, admin);
    		
    		request.setAttribute("admin",admin);
        }
		
		return "admin/info/updateSelf";
    	
        
        
    }
    
    
     

     
    

}
